import time

import uvicorn
from fastapi import FastAPI

app = FastAPI()

@app.get("/")
async def read_root():
    return {"message": "Welcome to FastAPI!"}

@app.get("/items/{item_id}")
async def read_item(item_id: int, q: str = None):
    start_time = time.time()
    print(time.time())
    await simulate_async_task()
    # test_read_item()
    end_time = time.time()
    return {"item_id": item_id, "q": q, "time": end_time - start_time}

async def simulate_async_task():
    import asyncio
    await asyncio.sleep(5)  # 模拟异步任务耗时

def test_read_item():
    time.sleep(5)  # 模拟测试用例耗时

if __name__ == "__main__":
    uvicorn.run(app, host="127.0.0.1", port=8000)
